package com.bool.tour;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.bool.tour.fragment.FindFragment;
import com.bool.tour.fragment.MainFragment;
import com.bool.tour.fragment.MeFragment;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    protected MainFragment mMainFragment = new MainFragment(); //首页
    protected FindFragment mFindFragment = new FindFragment();  //发现
    protected MeFragment mMeFragment = new MeFragment();        //我的

    protected LinearLayout mMenuHome;
    protected LinearLayout mMenuFind;
    protected LinearLayout mMenuMe;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        //获取Fragment
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container_content,mMainFragment)
                .add(R.id.container_content,mFindFragment)
                    .hide(mFindFragment)
                .add(R.id.container_content,mMeFragment)
                    .hide(mMeFragment)
                .commit();
    }

    /**
     * 初始化视图
     */
    public void initView(){
        mMenuHome = (LinearLayout) findViewById(R.id.menu_home);
        mMenuFind = (LinearLayout) findViewById(R.id.menu_find);
        mMenuMe = (LinearLayout) findViewById(R.id.menu_me);
        // 监控点击事件
        mMenuHome.setOnClickListener(this);
        mMenuFind.setOnClickListener(this);
        mMenuMe.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.menu_home:
                getSupportFragmentManager()
                        .beginTransaction()
                        .show(mMainFragment)
                        .hide(mFindFragment)
                        .hide(mMeFragment)
                        .commit();
                break;
            case R.id.menu_find:
                getSupportFragmentManager()
                        .beginTransaction()
                        .hide(mMainFragment)
                        .show(mFindFragment)
                        .hide(mMeFragment)
                        .commit();
                break;
            case R.id.menu_me:
                getSupportFragmentManager()
                        .beginTransaction()
                        .hide(mMainFragment)
                        .hide(mFindFragment)
                        .show(mMeFragment)
                        .commit();
                break;
        }
    }
}
